import game.banana.server.GameConstant;
import game.banana.server.game.BananaGame;
import game.banana.server.gameroom.BananaGameRoom;

import java.util.HashMap;
import java.util.Map;

import org.menacheri.jetserver.app.GameRoom;
import org.menacheri.jetserver.app.impl.GameRoomSession.GameRoomSessionBuilder;
import org.menacheri.jetserver.protocols.Protocol;
import org.menacheri.jetserver.service.impl.LookupService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.ImportResource;

@Configuration
@ImportResource("classpath:/server-beans.xml")
public class JetServerSpringConfig {
	@Autowired
	@Qualifier("messageBufferProtocol")
	private Protocol messageBufferProtocol;

	@Autowired
	@Qualifier("webSocketProtocol")
	private Protocol webSocketProtocol;

	public @Bean(name = "bananaGame") GameRoom getBananaGame() {
		GameRoomSessionBuilder sessionBuilder = new GameRoomSessionBuilder();
		sessionBuilder.parentGame(new BananaGame(GameConstant.BANANA_GAME, GameConstant.BANANA_GAME)).gameRoomName(GameConstant.BANANA_GAME).protocol(messageBufferProtocol);
		BananaGameRoom bananaGameRoom = new BananaGameRoom(sessionBuilder);
		return bananaGameRoom;
	}

	public @Bean(name = "lookupService")
	LookupService lookupService() {
		Map<String, GameRoom> refKeyGameRoomMap = new HashMap<String, GameRoom>();
		refKeyGameRoomMap.put(GameConstant.BANANA_GAME, getBananaGame());
		LookupService service = new LookupService(refKeyGameRoomMap);
		return service;
	}
}